/*
 * @Author: 闫聪敏
 * @Email: 
 * @Date: 2020-03-02 11:22:42
 * @Descripttion: 
 */
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormGroup, FormBuilder, Validators, AbstractControl, Form, FormControl } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd/message';
import { SubmaterialManageService } from 'src/app/material-manage/basedata-manage/submaterial-manage/submaterial-manage.service';
import { AccountaliasManageService } from 'src/app/material-manage/basedata-manage/accountalias-manage/accountalias-manage.service';
import { WorkManageService } from 'src/app/material-manage/basedata-manage/work-manage/work-manage.service';
import { DatePipe } from '@angular/common';
import { ApplyWareService } from 'src/app/material-manage/warehouse-manage/apply-ware/apply-ware.service';
import { MaterialRelationService } from '../../../basedata-manage/material-relation/material-relation.service';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { observable } from 'rxjs';
@Component({
  selector: 'app-apply-ware-outofstock',
  templateUrl: './apply-ware-outofstock.component.html',
  styleUrls: ['./apply-ware-outofstock.component.scss']
})
export class ApplyWareOutofstockComponent implements OnInit {
  billType: string = "1";
  remarks: string = "";
  //selectedDocumentCategories: string = "";
  modelType: number = 1;
  isOkLoading: boolean = false;
  AddWinIsView: boolean = false;
  AddForm: FormGroup;
  //#region 按钮，数据
  editDisabled: boolean = true;
  deleteDisabled: boolean = true;
  listData = [];
  //#endregion
  private infoId = "";

  isMatVisibleOut: boolean = false;

  //#region 全选，选中某行
  isAllChecked: boolean = false;

  modalDomBox: any;
  modalDomBoxAdd: any;
  constructor(
    private router: Router,
    private fb: FormBuilder,
    private submaterialManageService: SubmaterialManageService,
    private accountaliasManageService: AccountaliasManageService,
    private workManageService: WorkManageService,
    private applyWareService: ApplyWareService,

    private message: NzMessageService,
    private datePipe: DatePipe,
    private activeRouter: ActivatedRoute,
    private materialRelationService: MaterialRelationService,
    private modal: NzModalService,

  ) { }

  ngOnInit() {
    this.modalDomBox = document.querySelector("#modal_box");
    this.modalDomBoxAdd = document.querySelector("#modal_box_add");
    this.AddForm = this.fb.group({
      materialCode: [null, [Validators.required]],
      materialName: [null],
      warehouse: [null, [Validators.required]],
      warehouseAreaId: [null, [Validators.required]],
      unit: [null],
      accountAlias: [null, [Validators.required]],
      commandId: [null, [Validators.required]],
      codeBatch: [null, [Validators.required]],
      bucketCode: [null, [Validators.required]],
      pickType: [null, [Validators.required]],
      remarks: [null],
      demandNum: [null, [Validators.required, this.demandNumFn]],
      AvailableQuantity: [null],
      // ActualPickingQuantity: [null]
    });
    this.infoId = this.activeRouter.snapshot.paramMap.get('id');
    if (this.infoId != "" && this.infoId != null) {
      this.GetModel();
    }
    this.GetPickingType();
    this.GetMaterialInBillTypeEnum();
  }
  /**
     * @Author: 闫聪敏
     * @Email: 
     * @Date: 2020-03-05 14:34:06
     * @Descripttion:物料列表全选 
     * @Return: 
     */
  checkAll(value: boolean): void {
    this.listData.forEach(item => {
      item.checked = value;
    });
    if (value == true) {
      var count = this.listData.filter(s => s.checked);
      if (count.length != 0) {
        this.editDisabled = false;
        this.deleteDisabled = false;
      }
      if (count.length != 1) {
        this.editDisabled = true;
      }
    }
    else {
      this.editDisabled = true;
      this.deleteDisabled = true;
    }
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:33:14
   * @Descripttion:入库申请物料列表选中复选框 
   * @Return: 
   */
  SelectRow(): void {
    let _isAllCheck = true;
    this.listData.forEach(item => {
      if (!item.checked) {
        _isAllCheck = false;
      }
    })
    this.isAllChecked = _isAllCheck;
    var checkCount = this.listData.filter(item => item.checked).length;
    // 判断能否编辑或删除
    checkCount > 0 ? this.deleteDisabled = false : this.deleteDisabled = true;
    checkCount === 1 ? this.editDisabled = false : this.editDisabled = true;
  }
  //#endregion
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:32:55
   * @Descripttion:入库申请物料添加 
   * @Return: 
   */
  Add(): void {
    this.modelType = 1;
    this.AddWinIsView = true;
    this.AddForm.reset();
    this.GetAccountalias();
    this.GetWorkList();
    this.AddForm.patchValue({
      materialId: "",
      materialName: "",
      unit: "",
      warehouse: "",
      warehouseAreaId: "",

      accountAlias: "",
      commandId: "",
      materialCode: "",
      codeBatch: "",
      bucketCode: "",
      pickType: "",
      demandNum: ""
    });
  }
  editMaterialId = "";
  eidtIs = false;
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:32:18
   * @Descripttion: 出库物料编辑
   * @Return: 
   */
  async Edit() {
    this.eidtIs = true;
    this.modelType = 2;
    this.AddWinIsView = true;
    this.GetAccountalias();
    this.GetWorkList();
    this.GetPickingType();
   
    var checkEdit = this.listData.filter(s => s.checked);
    //this.selectedWarehouseModal(checkEdit[0].warehouseId)
    // this.GetAreaList(checkEdit[0].warehouseId);
    if (checkEdit.length == 1) {

      var data = checkEdit[0];
      console.log(data);
      await this.GetSpecList(data.materialId);
      await this.GetStorageListById(data.materialId);
      this.editMaterialId = data.materialId;
      this.materialCode=data.materialCode;
      this.AddForm.patchValue({
        accountAlias: data.accountAlias,
        materialId: data.materialId,
        materialCode: data.materialCode,
        materialName: data.materialName,
        codeBatch: data.bucketCode,
        commandId: data.commandId,
        unit: data.unit,
        warehouseAreaId: Number(data.warehouseAreaId),
        warehouse: Number(data.warehouseId),
        bucketCode: data.bucketCode,
        pickType: data.pickType,
        demandNum: data.demandNum,
        AvailableQuantity: data.availableNum,
        remarks: data.remarks,
      });
      await this.GetCodeBatchOrCount();
    }
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:35:46
   * @Descripttion: 取消按钮
   * @Return: 
   */
  handleCancel(): void {
    this.AddWinIsView = false;
    this.AddForm.patchValue({
      materialId: "",
      materialCode: "",
      materialName: "",
      unit: "",
      warehouse: "",
      warehouseAreaId: "",
      packageSpecId: "",
      bucketCode: "",
      commandId: "",
      accountAlias: "",
    });
    this.wareList = [];
    this.areaList = [];
    this.SpecList = [];
    this.AccountaliasList = [];
    this.WorkList = [];
  }

  productionDate: any;

  materialCode: string = "";
  private metList = [];
  newList = [];
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:36:03
   * @Descripttion: 确定按钮
   * @Return: 
   */
  handleOk(): void {
    for (const i in this.AddForm.controls) {
      this.AddForm.controls[i].markAsDirty();
      this.AddForm.controls[i].updateValueAndValidity();
    }
    if (this.AddForm.status == "VALID") {
      let _value = this.AddForm.value;
      this.isOkLoading = true;
      if (this.modelType == 1) {
        let _dataJson = {
          accountAlias: _value.accountAlias,
          accountAliasName: this.AccountaliasList.filter(s => s.id == _value.accountAlias)[0].alias,
          materialId: this.editMaterialId,
          materialCode: _value.materialCode,
          materialName: _value.materialName,
          codeBatch: _value.codeBatch,
          commandId: _value.commandId,
          commandName: _value.commandId != "" ? this.WorkList.filter(s => s.id == _value.commandId)[0].content : "",
          unit: _value.unit,
          pickType: _value.pickType,
          pickTypeName: this.GetPickingTypeList.filter(e => e.value == _value.pickType)[0].label,
          warehouseAreaId: _value.warehouseAreaId,
          warehouseId: _value.warehouse,
          warehouseName: this.wareList.filter(e => e.warehouseId == _value.warehouse)[0].warehouseName,
          warehouseAreaName: this.areaList.filter(e => e.warehouseAreaId == _value.warehouseAreaId)[0].warehouseAreaName,
          bucketCode: _value.bucketCode,
          checked: false,
          isDel: false,
          demandNum: _value.demandNum,
          AvailableQuantity:_value.AvailableQuantity,
          remarks:_value.remarks
        }
        console.log(_dataJson);
        this.metList.push(_dataJson);
      }
      else {
        var editModel = this.listData.filter(w => w.checked);
        if (editModel.length != 1) {
          this.message.warning("只能修改一条数据！");
          return;
        }
        else {
          var e = editModel[0];
          e.accountAlias = _value.accountAlias;
          e.materialId = this.editMaterialId;
          e.materialCode = _value.materialCode;
          e.materialName = _value.materialName;
          e.codeBatch = _value.codeBatch;
          e.commandId = _value.commandId;
          e.commandName = _value.commandId != "" ? this.WorkList.filter(s => s.id == _value.commandId)[0].content : "";
          e.unit = _value.unit;
          e.pickType = _value.pickType;
          e.pickTypeName = this.GetPickingTypeList.filter(e => e.value == _value.pickType)[0].label;
          e.warehouseAreaId = _value.warehouseAreaId;
          e.warehouseId = _value.warehouse;
          e.bucketCode = _value.bucketCode;
          e.checked = false;
          e.isDel = false;
          e.warehouseName = this.wareList.filter(e => e.warehouseId == _value.warehouse)[0].warehouseName;
          e.warehouseAreaName = this.areaList.filter(e => e.warehouseAreaId == _value.warehouseAreaId)[0].warehouseAreaName;
          e.demandNum = _value.demandNum,
          e.AvailableQuantity=_value.AvailableQuantity;
          e. remarks=_value.remarks;
        }
      }
      this.GetMetList();
      this.isOkLoading = false;
      this.isAllChecked = false;
      this.editDisabled = true;
      this.deleteDisabled = true;
      this.handleCancel();
    }
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:36:15
   * @Descripttion:取得物料列表 
   * @Return: 
   */
  GetMetList() {
    var res = this.metList.filter(e => !e.isDel);
    // res.forEach(item => {
    //   var w = this.formatDateYmr(item.productionDate);
    //   item.productionDate = w;
    // })
    this.listData = res;
    console.log(this.listData);
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:36:24
   * @Descripttion:  物料删除
   * @Return: 
   */
  Del() {
    let delModel = this.listData.filter(s => s.checked);
    if (delModel.length != 0) {
      delModel.forEach(item => {
        item.isDel = true;
      });
    }
    this.GetMetList();
    this.isAllChecked = false;
    this.editDisabled = true;
    this.deleteDisabled = true;
  }




  //库房列表
  wareList = [];
  wareId: any = "";
  GetWareList() {
    // this.wareList=this.NewStorageRoomList;
  }


  //#region 库房库区
  //NewStorageRoomList=[];
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:38:14
   * @Descripttion: 构造库房库区数据
   * @Return: 
   */
  StorageRoomAreaList = [];
  GetStorageListById(value: string) {

    return new Promise((resolve, reject) => {
      let dataAr = [];
      let data = {
        materialId: value,
        page: 0,
        size: 1000
      };
      this.wareList = [];

      this.submaterialManageService.GetStorageListById(data).subscribe(res => {
        resolve(res);
        this.wareList=[];
        this.StorageRoomAreaList = [];
        this.StorageRoomAreaList = res.content;
        this.StorageRoomAreaList.forEach(item => {
          let d = item.warehouseId;
          var houseId = this.wareList.filter(e => e.warehouseId == d);
          if (houseId.length == 0) {
            let areaList = [];
            areaList.push({
              "warehouseAreaId": item.warehouseAreaId,
              "warehouseAreaName": item.warehouseAreaName
            });
            var addDate = {
              "warehouseId": d,
              "warehouseName": item.warehouseName,
              "areaList": areaList
            }
            this.wareList.push(addDate);
          }
          else {
            let wareareaId = item.warehouseAreaId;
            var houseItem = this.wareList[0].areaList.filter(e => e.warehouseAreaId == wareareaId);
            if (houseItem.length == 0) {
              let newAreaModel = {
                warehouseAreaId: item.warehouseAreaId,
                warehouseAreaName: item.warehouseAreaName
              };
              this.wareList[0].areaList.push(newAreaModel);
              console.log(this.wareList[0]);
            }
          }
        });
      })
    });
    // this.wareList=dataAr;
    // return this.wareList;
  }
  //#endregion

  warehouseAreaId="";
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:38:32
   * @Descripttion: 选中某库房后执行操作 
   * @Return: 
   */
  selectedWarehouseModal(value: string) {
    this.wareId = value;
    this.GetAreaList(value);
  }

  /**
 * @Author: 闫聪敏
 * @Email: 
 * @Date: 2020-03-05 14:38:32
 * @Descripttion: 选中某库房后执行操作 
 * @Return: 
 */
  aredIdSelId = "";
  selectedWarehouseAreaIdModal(value: string) {
    this.aredIdSelId = value;
    this.GetCodeBatchOrCount();
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:39:02
   * @Descripttion: 获取库区数据
   * @Return: 
   */
  areaList = [];
  GetAreaList(value: any) {
    let t: any = this.wareList.filter(s => s.warehouseId == value);
    if (t.length == 0) {
      return;
    }
  //  this.AddForm.reset();
    
    this.areaList = t[0].areaList;
  }


  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:39:15
   * @Descripttion: 取得规格列表
   * @Return: 
   */
  SpecList = [];
  GetSpecList(value: string) {
    let data = {
      materialId: value,
      page: 0,
      size: 1000
    };
    this.submaterialManageService.GetSpeList(data).subscribe(res => {
      this.SpecList = res.content;
    });
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:39:25
   * @Descripttion: 取得别名列表
   * @Return: 
   */
  AccountaliasList = [];
  GetAccountalias() {
    let data = {
      alias: "",
      page: 0,
      size: 100
    }
    this.accountaliasManageService.getFindAll(data).subscribe(res => {
      this.AccountaliasList = res.content;
    });
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:39:38
   * @Descripttion: 取得工作令
   * @Return: 
   */
  WorkList = [];
  GetWorkList(): void {
    let data = {
      code: "",
      content: "",
      page: 0,
      size: 100,
    }
    this.workManageService.apiList(data).subscribe(res => {
      this.WorkList = res.content;
    });
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:39:59
   * @Descripttion: 点击有效期后执行
   * @Return: 
   */
  onDateChange(result: Date): void {
    let time = this.formatDate(result)
    this.productionDate = time;
  }
  // 时间格式化
  formatDate(date) {
    return this.datePipe.transform(date, 'yyyy-MM-dd hh:mm:ss');
  }
  // 时间格式化
  formatDateYmr(date) {
    return this.datePipe.transform(date, 'yyyy-MM-dd');
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:40:15
   * @Descripttion: 点击取消后执行跳转
   * @Return: 
   */
  Cancel(): void {
    this.router.navigate(['/material/warehouse/applyware']);
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:40:37
   * @Descripttion: 点击修改取得详情
   * @Return: 
   */
  GetModel() {
    let data = {
      id: this.infoId
    }
    this.applyWareService.GetModel(data).subscribe(res => {
      // res.expiryDate = this.formatDateYmr(res.expiryDate);
      this.billType = String(res.billType);
      this.remarks = res.remarks;
      res.details.forEach(_value => {
        let _dataJson = {
          accountAlias: _value.accountAlias,
          accountAliasName: _value.accountAliasName,
          materialId: _value.materialId,
          materialCode: _value.materialCode,
          materialName: _value.materialName,
          codeBatch: _value.codeBatch,
          commandId: _value.commandId,
          commandName: _value.commandName,
          unit: _value.unit,
          pickType: _value.pickType,
          pickTypeName: this.GetPickingTypeList.filter(s => s.value == _value.pickType)[0].label,
          warehouseAreaId: _value.warehouseAreaId,
          warehouseId: _value.warehouseId,
          warehouseName: _value.warehouseName,
          warehouseAreaName: _value.warehouseAreaName,
          bucketCode: _value.printCode,
          demandNum: _value.demandNum,
          availableNum: _value.availableNum,
          AvailableQuantity:_value.availableNum,
          checked: false,
          isDel: false,
          remarks:_value.remarks,
          useNum:_value.useNum
        }
        console.log(_dataJson);
        this.metList.push(_dataJson);
      });
      this.GetMetList();
    });
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:41:03
   * @Descripttion: 点击保存后，添加数据
   * @Return: 
   */
  Save(): void {
    if (this.billType == "") {
      this.message.warning("请选择单据类别！");
      return;
    }
    let addDate = this.listData.filter(s => !s.isDel);
    if (addDate.length == 0) {
      this.modal.warning({
        nzTitle: "保存提示",
        nzContent: "请正确添加物料信息"
      })
      return;
    }
    var dataJson = {
      "billType": this.billType,
      "remarks": this.remarks,
      "details": this.listData.filter(w => !w.isDel)
    }
    console.log(dataJson);
    if (this.infoId != "" && this.infoId != null) {
      this.applyWareService.editOut(dataJson, this.infoId).subscribe(async res => {
        console.log(res);
        this.router.navigate(['/material/warehouse/applyware']);
      });
    }
    else {
      this.applyWareService.addOut(dataJson).subscribe(async res => {
        this.router.navigate(['/material/warehouse/applyware']);
      });
    }

  }

  //#region 物料选择
  showMatModal(): void {
    this.getAltMaterialData();
    this.isMatVisibleOut = true;
  }
  handlematerielCancel(): void {
    this.AddForm.patchValue({
      materialId: "",
      materialCode: "",
      materialName: "",
      unit: "",
      warehouse: "",
      warehouseAreaId: "",
      packageSpecId: "",
      bucketCode: "",
      commandId: "",
      accountAlias: "",
    });
    this.wareList = [];
    this.areaList = [];
    this.SpecList = [];
    this.AccountaliasList = [];
    this.WorkList = [];
    this.isMatVisibleOut = false;
  }

  txtAltMatCode: string = "";
  txtAltMatName: string = "";
  //数据列表
  altMatPageIndex: any = '1';//table当前页
  altMatPageSize: any = '10';//table每页条数
  altMatTotalSize: any = '';//总共条数
  altMatListOfData = [];
  selMaterialObj = {};
  //hidMatetialId: string = '';
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-06 17:13:24
   * @Descripttion: 物料列表数据 
   * @Return: 
   */
  getAltMaterialData() {
    let data = {
      code: this.txtAltMatCode,
      name: this.txtAltMatName,
      page: this.altMatPageIndex - 1 < 0 ? 0 : this.altMatPageIndex - 1,
      size: this.altMatPageSize
    }
    this.submaterialManageService.apiList(data).subscribe(res => {
      res.content.forEach(item => {
        item.checked = false;
      })
      this.altMatTotalSize = res.totalElements
      this.altMatListOfData = res.content;
    });
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:36:51
   * @Descripttion: table页码点击事件
   * @Return: 
   */
  altMatClickPage(current) {
    this.altMatPageIndex = current
    this.getAltMaterialData()
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:36:59
   * @Descripttion:  物料搜索
   * @Return: 
   */
  getAltMatSearchData() {
    this.altMatPageIndex = 1;
    this.getAltMaterialData();
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:37:16
   * @Descripttion: 物料点击确定
   * @Return: 
   */
  matHandleOk(): void {
    let checked = false;
    this.AddForm.reset();
    this.altMatListOfData.forEach(item => {
      if (item.checked) {
        checked = true;
        this.editMaterialId = item.id;
        this.materialCode = item.code;
        this.AddForm.patchValue({
          materialId: item.id,
          materialCode: item.code,
          materialName: item.name,
          unit: item.unit,
          warehouse: "",
          warehouseAreaId: "",
          packageSpecId: "",
          codeBatch: "",
          bucketCode: "",
          commandId: "",
          accountAlias: "",
          pickType: ""
        });
        this.areaList = [];
        // this.AddForm.get('materialId').setValue(item.code);
        // this.AddForm.get('materialName').setValue(item.name);
        // this.AddForm.get('unit').setValue(item.unit);
        // this.AddForm.get('warehouse').setValue("");
        // var t = this.metList.filter(e => e.materialId == this.editMaterialId);
        // if (t.length != 0) {
        //   this.message.warning("物料已存在！");
        //   return;
        // }
        // this.isMatVisibleOut = false;
      }
    });

    var t = this.metList.filter(e => e.materialId == this.editMaterialId);
    if (t.length != 0) {
      this.message.warning("物料已存在！");
    }
    else {
      this.isMatVisibleOut = false;
      if (!checked) {
        this.message.warning("请选择物料！");
      }
      this.GetStorageListById(this.editMaterialId);
      this.GetSpecList(this.editMaterialId);
    }
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:37:31
   * @Descripttion: 物料点击取消
   * @Return: 
   */
  matHandleCancel(): void {
    this.isMatVisibleOut = false;
    
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-05 14:37:45
   * @Descripttion: 物料选中复选框某一行
   * @Return: 
   */
  altMatCheckSingle(data) {
    this.altMatListOfData.forEach(item => {
      if (item.checked) {
        item.checked = false;
      }
    })
    this.selMaterialObj = data;
    data.checked = true;
  }
  //#endregion


  //#region  
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-09 10:05:29
   * @Descripttion: 获取挑库类型
   * @Return: 
   */
  GetPickingTypeList = [];
  async GetPickingType() {
    let list: any = await this.submaterialManageService.getclTypeList('picking_type');
    this.GetPickingTypeList = list.content
  }

  barcodeList = [];
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-09 10:05:02
   * @Descripttion: 获取条码批次和可用数量
   * @Return: 
   */
  async GetCodeBatchOrCount() {
    var dataJson = {
      "materialId": this.editMaterialId,
      "warehouseAreaId": Number(this.aredIdSelId),
      "warehouseId": Number(this.wareId)
    }
  
    console.log(dataJson);
    let listData = [];
    this.materialRelationService.findStockBatchByIds(dataJson).subscribe(res => {
      if (res.length != 0) {
        res.forEach(item => {
          listData.push(item);
        });
        this.barcodeList=listData;
        // let data = res[0];
        // this.AddForm.patchValue({
        //   AvailableQuantity: data.weight,
        //   codeBatch: data.barcodeBatch,
        //   bucketCode: this.materialCode + "00" + data.barcodeBatch
        // });
      }
      else
      {
        // this.AddForm.get("pickType").setValue("");
        // this.AddForm.get("codeBatch").setValue("");
        this.barcodeList=[];
      }
    })
  }
  //#endregion

  selectOnBarcodeList(data) {
    let list = this.barcodeList.filter(d => d.barcodeBatch == data);
    if (list.length != 0) {
      this.AddForm.get("AvailableQuantity").setValue(list[0].weight);
      this.AddForm.get("bucketCode").setValue(this.materialCode + "00" + data);
    }
  }
  nzDisabled=true;
  selectedPickType(data)
  {
    if (data==1) {
      this.nzDisabled=true;
     if( this.barcodeList.length!=0)
     {
      let data = this.barcodeList[0];
      this.AddForm.patchValue({
        AvailableQuantity: data.weight,
        codeBatch: data.barcodeBatch,
        bucketCode: this.materialCode + "00" + data.barcodeBatch
      });
     }
    } else if(data==2) {
      this.nzDisabled=false;
    }
    else
    {
      this.nzDisabled=true;
    }
  }
  /**
   * @Author: 闫聪敏
   * @Email: 
   * @Date: 2020-03-09 14:13:12
   * @Descripttion: 自定义验证需求量
   * @Return: 
   */
  demandNumFn = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else {
      let count = Number(this.AddForm.controls.AvailableQuantity.value);
      if (control.value > count) {
        return { confirm: true, error: true };
      }
    }
    return {};
  };
  MaterialInBillTypeEnum = [];
  GetMaterialInBillTypeEnum() {
    let MaterialInBillTypeEnumPri = [];
    let data = {};
    data = {
      enumName: "MaterialOutBillTypeEnum"
    }
    this.applyWareService.GetEnum(data).subscribe(res => {
      for (const key in res) {
        var e = { key: key, value: res[key] }
        MaterialInBillTypeEnumPri.push(e);
      }
      this.MaterialInBillTypeEnum = MaterialInBillTypeEnumPri
    });
  }
}
